
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common/common.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>

<link rel="stylesheet" type="text/css" href="<%=ApplicationPath%>/css/easyui.multiple.combobox.css" />
<script type="text/javascript" src="<%=jsPath%>/jquery/jquery.timers.js"></script><!--定时器-->
<script type="text/javascript" src="<%=jsPath%>/terminalCommand.js?v=801"></script><!--终端命令结果查询-->
</head>

		<script type="text/javascript" charset="utf-8">
		 
var mediaId = -1;
//当检索命令执行成功时
function onSearchSuccess(result)
{
	
	var queryGrid = $("#queryGrid");
	var ack = result.data;
	if(ack.data)
	{
		mediaId = -1;
		$(".commandMsg").html(ack.status);
		var channelNo = $("#channel").val();
		//alert(channelNo);
		if(channelNo != 0)
		{
			var filterData = new Array();
			for(var m = 0; m < ack.data.length; m++)
			{
				var rowData = ack.data[m];
				if(rowData.channelId == channelNo)
				{
					filterData.push(rowData);
				}
			}
			ack.data = filterData;
		}
		queryGrid.datagrid("loadData",{rows:ack.data});
	}
}


function  onUploadCommandSuccess(result) {
    //console.log(result.data);
    $("#btnPause").enable();
    $("#btnCancel").enable();
}

function  onControlSuccess(result) {

}

function uploadSingle()
{
	if(mediaId < 0)
	{
		$.messager.alert("提示","请选择多媒体记录");
		return;
	}
	var taskCondition = $("#taskCondition").val();//"0,1,2";
	var params = {resourceId:mediaId,taskCondition:taskCondition};
	var url = "<%=ApplicationPath%>/videoDownload/ftpUploadByResourceId.action";
	$.getJSON(url, params, function(result)
	{
		if (result.success) {
			commandId = result.data; //下发成功后，获取到命令Id
			TerminalCommand.commandButton = $("#btnUploadSingle");
			TerminalCommand.times=60;
			var url = null;
			TerminalCommand.startQueryResult(commandId, url, onUploadCommandSuccess);//命令下发成功,根据命令id,开始尝试获取检索结果
		}else {
			$(".commandMsg").html("提交失败! 错误原因：" + (result.message ? result.message : result.Data));
			//停止所有的在$('body')上定时器  
			$('body').stopTime ();  
	    }

	});
}


function selectMedia(_mediaId)
{
	mediaId = _mediaId;
}

function initAlarmCombobox()
{
    $('#alarm').combobox({
        url:'<%=ApplicationPath%>/alarmConfig/terminalAlarmTypeList.action',
        method:'get',
        valueField:'id',
        textField:'text',
        panelHeight:'auto',
        multiple:true,
        formatter: function (row) {
            var opts = $(this).combobox('options');
            return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField]
        },

        onShowPanel: function () {
            var opts = $(this).combobox('options');
            var target = this;
            var values = $(target).combobox('getValues');
            $.map(values, function (value) {
                var el = opts.finder.getEl(target, value);
                el.find('input.combobox-checkbox')._propAttr('checked', true);
            })
        },
        onLoadSuccess: function () {
            var opts = $(this).combobox('options');
            var target = this;
            var values = $(target).combobox('getValues');
            $.map(values, function (value) {
                var el = opts.finder.getEl(target, value);
                el.find('input.combobox-checkbox')._propAttr('checked', true);
            })
        },
        onSelect: function (row) {
            //console.log(row);
            var opts = $(this).combobox('options');
            var el = opts.finder.getEl(this, row[opts.valueField]);
            el.find('input.combobox-checkbox')._propAttr('checked', true);
        },
        onUnselect: function (row) {
            var opts = $(this).combobox('options');
            var el = opts.finder.getEl(this, row[opts.valueField]);
            el.find('input.combobox-checkbox')._propAttr('checked', false);
        }
    });
}

function controlUpload(controlCmd,cmdId)
{
    if(!cmdId)
        cmdId = commandId;
    if(cmdId <= 0)
    {
        $.messager.alert("提示","上传命令没有执行成功，不能暂停或取消");
        return;
    }

    if(controlCmd != 2)
    {
        var btnName = $("#btnPause").val();
        controlCmd = btnName == "暂停" ? 0 :1;
        btnName = btnName == "暂停" ? "继续" : "暂停";
        $("#btnPause").val(btnName);
    }
    var params = {commandId:cmdId,controlCmd:controlCmd,vehicleId:'${vehicleId}'};
    var url = "<%=ApplicationPath%>/videoDownload/controlUpload.action";
    $.getJSON(url, params, function(result)
    {
        if (result.success) {
            var commandId = result.data; //下发成功后，获取到命令Id
            if(controlCmd ==0 || controlCmd == 1)
                TerminalCommand.commandButton = $("#btnPause");
            else
                TerminalCommand.commandButton = $("#btnCancel");

            TerminalCommand.startQueryResult(commandId,null, onControlSuccess);//命令下发成功,根据命令id,开始尝试获取检索结果
        }else {
            $(".commandMsg").html("提交失败! 错误原因：" + (result.message ? result.message : result.Data));
            //停止所有的在$('body')上定时器
            $('body').stopTime ();
        }

    });
}

function initAlarmTypeList(alarmTypeList)
{
    $('#alarm').combotree({
        valueField: "alarmType", //Value字段
        textField: "name", //Text字段
        multiple: true,
        data: alarmTypeList,
        onCheck: function (node, checked) {
            //让全选不显示
            $("#alarm").combotree("setText", $("#alarm").combobox("getText").toString().replace("全选,", ""));
            var values = $('#alarm').combotree("getValues");
            var strAlarm = values.join(",");
            $("#alarmStatus").val(strAlarm);
        },
        onClick: function (node, checked) {
            //让全选不显示
            $("#alarm").combotree("setText", $("#alarm").combobox("getText").toString().replace("全选,", ""));
        }
    });
    $("#alarm").combotree("setText","不指定报警");
}

//下载任务执行条件下拉框
function initTaskCondition()
{
    $('#taskCombo').combotree({
        multiple: true,
        data: [{id:0,text:"WIFI下可下载"},{id:1,text:"有线连接时可下载"},{id:2,text:"无线3G/4G连接时可下载"}],
        onCheck: function (node, checked) {
            //让全选不显示
            $("#taskCombo").combotree("setText", $("#taskCombo").combobox("getText").toString().replace("全选,", ""));
            var values = $('#taskCombo').combotree("getValues");
            var taskCondition = values.join(",");
            $("#taskCondition").val(taskCondition);
        },
        onClick: function (node, checked) {
            //让全选不显示
            $("#taskCombo").combotree("setText", $("#taskCombo").combobox("getText").toString().replace("全选,", ""));
        }
    });

    //$("#taskCombo").combotree("setText","所有条件");
    $("#taskCombo",[0,1,2]).combotree('setValues',[0,1,2]);
    $("#taskCondition").val("0,1,2");

}
//编辑列
			function getRadioColumn(value, rowData, rowIndex)
			{
				var mediaId = rowData.entityId;
				var html =   '<input type="radio" name="selectRadio" onclick="selectMedia(' + mediaId + ');"    value="' + mediaId + '" />';
				return html;

			}


			$(document).ready(function() {
				 $("#entityForm").validate(); //初始化验证信息
				var url = '<%=ApplicationPath%>/alarmConfig/terminalAlarmTypeList.action';
				$.getJSON(url, null, function(result)
				{
				    if(result.success)
					{
					    initAlarmTypeList(result.data);
					}
				});
                $("#channel").fillVehicleChannels({vehicleId:"${vehicleId}"},"0");

                $("#btnQueryFtpFileList").click(function()
				{
				    InfoWindow.viewFtpFileList("${vehicleId}");
                });

				 var defaultRoleId = "";//${roleId}; //取出当前车辆的车牌颜色，默认选中
				//ajax填充下拉框数据 填充监听类型 选项
				 $("#eventType").lookup({category:"MediaEvent", selectedValue:1});
				 $("#videoDataType").lookup({category:"videoDataType", selectedValue:1});

				 var now = Utility.today(1);
				 var strDate = now + " 23:59:00";
				  $("#endDate").datetimebox('setValue', strDate);	
				  var now = Utility.today();
				 strDate = (now + " 00:00:00");
				  $("#startDate").datetimebox('setValue', strDate);
				 // $("#btnSearch :last-child").text("cest");
                //document.getElementById("btnSearch").lastChild.textContent = "cestt";
                initTaskCondition();
	             Utility.ajaxSubmitForm("entityForm", {
						 success:function(responseText)
						 {
							   var result = responseText;
								if (result.success) {
									 //alert("命令已经下发,请等待处理!");
									 var commandId = result.data; //下发成功后，获取到命令Id
			                         TerminalCommand.commandButton = $("#btnSearch");
                                     var url = "<%=ApplicationPath%>/videoResourceSearch/getVideoResourceList.action";
									 TerminalCommand.startQueryResult(commandId,url,onSearchSuccess);//命令下发成功,根据命令id,开始尝试获取检索结果
								}
								else {
									$(".commandMsg").html("提交失败! 错误原因：" + (result.message ? result.message : result.Data));
									//停止所有的在$('body')上定时器  
									$('body').stopTime ();  
								  }
						 }
				 });
			} );
		</script>
<body>
		<div id="toolbar" >		
			
		<form id="entityForm" name="entityForm" 
			action='<%=ApplicationPath%>/videoResourceSearch/sendRequest.action' method="POST">
				
        <input type="hidden"  name="vehicleId"  id="vehicleId" value="${vehicleId}"/>
			<input type="hidden"  name="taskCondition"  id="taskCondition" value="0,1,2"/>
			<input type="hidden"  name="alarmStatus"  id="alarmStatus" value=""/>
  <table width="100%"  class="TableBlock">
					<tbody><tr>
						<td colspan="8" style="font-weight: bold; background: #EFEFEF;" height="25">音视频文件检索
						<span style="color:red;background:blue;">${message}</span>
						</td>
					</tr>
					<tr>
						<td align="right">通道
							:</td>
						<td>
						 <select id="channel" name="channel">
							</select>
							</td>
						<td align="right"><input type="checkbox" name="enableDateCondition" value="true" checked />查询时间:</td>
						<td colspan="7">
							<input class="easyui-datetimebox" name="startDate" id="startDate" required style="width:160px" value=""></input>
							至
							<input class="easyui-datetimebox" name="endDate" id="endDate" required style="width:160px" value=""></input>

						</td>

						   
					</tr>
					<tr>

						<td>报警标志</td>
						<td>
							<select id="alarm" class="easyui-combotree" style="width: 200px; height: 24px;">
							</select>
						</td>

						<td align="right">音视频类型
							:</td>
						<td><select id="videoType"  style="width: 150px;" name="videoType">
							<option value="0" selected>音视频</option>
							<option value="1">音频</option>
							<option value="2">视频</option>
							<option value="3">视频或音视频</option>
						</select></td>
						</tr>
					<tr>



						<td>码流类型:</td>
						<td colspan=1>
							<select name="streamType" id="streamType">
								<option value="0" selected>所有码流</option>
								<option value="1" >主码流</option>
								<option value="2">子码流</option>
							</select>
						</td>
						<td>存储器类型:</td>
						<td colspan=1>
							<select name="storeType" id="storeType">
								<option value="0" selected>所有</option>
								<option value="1">主存储器</option>
								<option value="2">备用存储器</option>
							</select>
						</td>
						<td align="right">任务执行条件</td>
						<td>
							<select id="taskCombo" class="easyui-combotree" style="width: 200px; height: 24px;">
							</select>
						</td>
					</tr>
					<tr>
					  <td colspan=8>

						  <button id="btnSearch" type="submit" class="button green medium sendjson" ><i class="fa fa-check" style="margin-right:3px;"></i> 检索</button>

					      <input type="button"  id="btnUploadSingle" value="上传所选多媒体" onclick="uploadSingle();">
						  <input type="button"  id="btnPause" value="暂停上传" disabled onclick="controlUpload(0);">
						  &nbsp;&nbsp;
						  <input type="button" id="btnCancel"  value="取消上传" onclick="controlUpload(2);">
						  &nbsp;&nbsp;
						  <input type="button" value="查询文件上传状态"  title="查询" id="btnQueryFtpFileList" />&nbsp;&nbsp;

						  <span class="commandMsg"></span> 
					  </td>

				</tbody></table>
				</form>
			</div>	
				<table id="queryGrid" class="easyui-datagrid" 
						data-options="singleSelect:true,rownumbers:true,striped:true,fitColumns: true,fit:true,toolbar:'#toolbar',
						url:'',method:'get'">
					<thead>
						<tr>
							<th data-options="field:'1',formatter:getRadioColumn" width="5%">选择</th>
							<th data-options="field:'channelId'" width="5%">通道号</th>
							<th data-options="field:'startDate'" width="15%">开始时间</th>
							<th data-options="field:'endDate'" width="15%">结束时间</th>
							<th data-options="field:'alarmStatus'" width="15%">报警标志</th>
							<th data-options="field:'dataType'" width="8%">资源类型</th>
							<th data-options="field:'streamType'" width="8%">码流类型</th>
							<th data-options="field:'storeType'" width="8%">存储器类型</th>
							<th data-options="field:'fileLength'" width="10%">文件大小</th>
						</tr>
					</thead>
					<tbody>
						
					</tbody>					
				</table>
</body>

